import { Enemy } from '../classes/Enemy';

export class EnemyFactory {
  // 敌人类型配置
  private enemyTypes = [
    { name: '史莱姆', baseHealth: 30, baseAttack: 5, baseDefense: 2 },
    { name: '哥布林', baseHealth: 45, baseAttack: 8, baseDefense: 3 },
    { name: '骷髅兵', baseHealth: 60, baseAttack: 10, baseDefense: 5 },
    { name: '狼人', baseHealth: 80, baseAttack: 15, baseDefense: 7 },
    { name: '魔法师', baseHealth: 50, baseAttack: 20, baseDefense: 2 }
  ];

  // BOSS类型配置
  private bossTypes = [
    { name: '恶魔领主', baseHealth: 200, baseAttack: 30, baseDefense: 15 },
    { name: '远古巨龙', baseHealth: 300, baseAttack: 40, baseDefense: 20 },
    { name: '死亡骑士', baseHealth: 250, baseAttack: 35, baseDefense: 25 }
  ];

  // 创建随机敌人
  createRandomEnemy(stageLevel: number): Enemy {
    // 随机选择敌人类型
    const randomType = this.enemyTypes[Math.floor(Math.random() * this.enemyTypes.length)];
    
    // 根据关卡调整难度
    const levelMultiplier = 1 + (stageLevel - 1) * 0.3;
    
    // 计算属性
    const health = Math.floor(randomType.baseHealth * levelMultiplier * (0.8 + Math.random() * 0.4));
    const attack = Math.floor(randomType.baseAttack * levelMultiplier * (0.8 + Math.random() * 0.4));
    const defense = Math.floor(randomType.baseDefense * levelMultiplier * (0.8 + Math.random() * 0.4));
    const experience = Math.floor((health + attack + defense) * 0.5);
    
    return new Enemy(randomType.name, health, attack, defense, experience);
  }

  // 创建BOSS敌人
  createBoss(stageLevel: number): Enemy {
    // 根据关卡选择合适的BOSS
    const bossIndex = Math.min(stageLevel - 1, this.bossTypes.length - 1);
    const bossType = this.bossTypes[bossIndex];
    
    // 根据关卡调整难度
    const levelMultiplier = 1 + (stageLevel - 1) * 0.5;
    
    // 计算属性（BOSS属性比普通敌人高很多）
    const health = Math.floor(bossType.baseHealth * levelMultiplier);
    const attack = Math.floor(bossType.baseAttack * levelMultiplier);
    const defense = Math.floor(bossType.baseDefense * levelMultiplier);
    const experience = Math.floor((health + attack + defense) * 2); // BOSS给予更多经验
    
    return new Enemy(`${bossType.name}`, health, attack, defense, experience);
  }
}